package com.software.shipper.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

import com.software.common.CommonUtils;
import com.software.form.cargobooking.dao.CargoBookingTransaction;

public class CargoServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doGet(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		CargoBookingTransaction cbt = (CargoBookingTransaction) CommonUtils.getBean("cargoBookingTransaction");
		JSONObject json = CommonUtils.readJSONStringFromRequestBody(request, response);
		try{
			String no = json.getString("no");
			String shipper = json.getString("shipper");
			String shipper_addr = json.getString("shipper_addr");
			String con = json.getString("con");
			String dest = json.getString("dest");
			String con_addr = json.getString("con_addr");
			String departure = json.getString("departure");
			String spec = json.getString("spec");
			String name = json.getString("name");
			String pieces = json.getString("pieces");
			String weight = json.getString("weight");
			String m3 = json.getString("m3");
			String charges = json.getString("charges");
			String semail = json.getString("semail");
			String saemail = json.getString("saemail");
			if(cbt.add(no, shipper, shipper_addr, con, dest, con_addr, departure, spec, name, pieces, weight, m3, charges, semail, saemail))
				CommonUtils.outputJsonData(1, response);
			else
				CommonUtils.outputJsonData(0, response);
		}catch(JSONException je){
			try {
				CommonUtils.outputJsonData(0, response);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
